﻿using Pay.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Pay.DTO;
using Pay.TO;
using Pay.Token.Utils;
using System.Threading.Tasks;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using Flurl.Http;
using Pay.Core;

namespace Pay.Token.Controllers
{
    /// <summary>
    /// 拓垦分销商城
    /// </summary>
    [AppAuthorize("Member")]
    public class TopicController : GeneralController {
        private IProductService _iProductService;
        private IOrderService _iOrderService;
        private IMerchantService _iMerchantService;
        private IRedRecordService _iRedRecordService;
        private ITokenShopSubjectService _iTokenShopSubjectService;

        public TopicController(IProductService iProductService, IOrderService iOrderService, 
            IMerchantService iMerchantService, ITokenShopSubjectService iTokenShopSubjectService
            , IRedRecordService iRedRecordService) {
            _iProductService = iProductService;
            _iOrderService = iOrderService;
            _iMerchantService = iMerchantService;
            _iTokenShopSubjectService = iTokenShopSubjectService;
            _iRedRecordService = iRedRecordService;
        }

        /// <summary>
        /// 专题商品列表
        /// </summary>
        /// <returns></returns>
        [HttpGet, AllowAnonymous]
        public ActionResult TopicProduct(long subject_id) {
            ViewBag.img_url = RequestMethod.token_imgurl;
            merchant_dto merchant = new merchant_dto();
            red_user_dto redcord = new red_user_dto();
            if (UserId > 0) {
                merchant = _iMerchantService.Get(UserId);
                redcord = _iRedRecordService.GetUser(UserId);
            }
            ViewBag.merchant = merchant;
            ViewBag.redcord = redcord;
            ViewBag.subject_id = subject_id;
            ViewBag.topic = _iTokenShopSubjectService.GetTokenShopSubject(subject_id);
            return View();
        }
        [AllowAnonymous]
        public PartialViewResult _TopicProduct(TokenShopSubjectProductQuery query) {
            var merchant = _iMerchantService.Get(t_RequestMethod.merchant_no);
            query.pageviews_num = true;
            var list = _iTokenShopSubjectService.GetSubjectProducts(query);
            ViewBag.img_url = RequestMethod.token_imgurl;
            ViewBag.shop_id = query.shop_id.GetValueOrDefault(0);
            int userType = 0;
            if (UserId > 0) {
                var curMerchant = _iMerchantService.Get(UserId);
                userType = (int)curMerchant.usertype;
            }
            ViewBag.UserType = userType;
            return PartialView(list);
        }
    }
}